﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.OMM.HealthMonitor.Entity.Common;
using Sinacor.OMM.HealthMonitor.Entity.Msmq;

namespace Sinacor.OMM.HealthMonitor.Entity.HftProcessor
{
    [Serializable()]
    public class HftProcessorData : HealthEntityBase, IHealthDataReset
    {
        public HftProcessorData()
            : base(HealthType.HftProcessor)
        {
            Msmq = new MsmqData(this);
            ProcessData = new ProcessData(this);
            MessageProcessor = new MessageProcessor(this);
            Database = new DataBase(this);
            DistributionRules = new List<DistributionRules>();
            ErrorData = new ErrorData(this);
        }

        MsmqData _msmq;
        public MsmqData Msmq
        {
            get { return _msmq; }
            set
            {
                _msmq = value;
                this.LastUpdate = DateTime.Now;
            }
        }

        //Número de Tentativas Reconexão com MSMQ (Fila HFT1)
        private long _totalMsmqConnectionRetries;
        public long TotalMsmqConnectionRetries
        {
            get { return _totalMsmqConnectionRetries; }
            set
            {
                _totalMsmqConnectionRetries = value;
                this.LastUpdate = DateTime.Now;
            }
        }

        MessageProcessor _messageProcessor;
        public MessageProcessor MessageProcessor
        {
            get { return _messageProcessor; }
            set
            {
                _messageProcessor = value;
                this.LastUpdate = DateTime.Now;
            }
        }

        DataBase _database;
        public DataBase Database
        {
            get { return _database; }
            set
            {
                _database = value;
                this.LastUpdate = DateTime.Now;
            }
        }

        ProcessData _processData;
        public ProcessData ProcessData
        {
            get { return _processData; }
            set
            {
                _processData = value;
                this.LastUpdate = DateTime.Now;
            }
        }


        public string HftId
        {
            get
            {
                return ProcessData.MachineMacAddress + ProcessData.ProcessId + ProcessData.ThreadId;
            }

        }

        private List<DistributionRules> _distributionRules;

        public List<DistributionRules> DistributionRules
        {
            get { return _distributionRules; }
            set 
            { 
                _distributionRules = value;
                this.LastUpdate = DateTime.Now;
            }
        }

        private ErrorData _errorData;

        public ErrorData ErrorData
        {
            get { return _errorData; }
            set
            {
                _errorData = value;
                this.LastUpdate = DateTime.Now;
            }
        }

        public Int32 NumberofHftProcess
        {
            get;
            set;
        }

        public void Reset()
        {
            ErrorData.Reset();
            Msmq.Reset();
            TotalMsmqConnectionRetries = 0;
            MessageProcessor.Reset();
            Database.Reset();
            ProcessData.Reset();
        }
    }
}
